package com.meizi.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 枚举 就诊人表 的 性别:1-男 2-女 0-未知 
 * 
 * @author Code Pioneer 
 */
public enum PatientMemberGenderEnum {

	BOY(1, "男"),

	GIRL(2, "女"),

	NO(0, "未知"),

	; 

	private Integer value;

	private String desc;

	/**
	 * 枚举缓存
	 */
	private static volatile List<Map<String, Object>> cache = null;


	PatientMemberGenderEnum(Integer value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	/**
	 * 根据 value 找 对应的枚举
	 * 
	 * @param v Integer 
	 * @return PatientMemberGenderEnum
	 */
	public static PatientMemberGenderEnum from(Integer v) {
		for (PatientMemberGenderEnum tt : PatientMemberGenderEnum.values()){
			if (tt.getValue().equals(v)){
				return tt;
			}
		}
		throw new IllegalArgumentException("unknown trade type: " + v);
	}

	/**
	 * 查找 value 是否存在
	 * 
	 * @param value Integer 参数
	 * @return boolean
	 */
	public static boolean containsValue(Integer value) {
		PatientMemberGenderEnum[] values = PatientMemberGenderEnum.values();
		for (PatientMemberGenderEnum e : values) {
			if (e.getValue().equals(value)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 查找 value 是否存在
	 * 
	 * @param value Integer 参数
	 * @return boolean
	 */
	public static boolean validation(Integer value) {
		boolean b = containsValue(value);
		return b;
	}

	/**
	 * 查找 desc 是否存在
	 * 
	 * @param desc String 参数
	 * @return boolean
	 */
	public static boolean containsDesc(String desc) {
		PatientMemberGenderEnum[] values = PatientMemberGenderEnum.values();
		for (PatientMemberGenderEnum e : values) {
			if (e.getDesc().equals(desc)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * To Dict
	 * @return List<Map<String, Object>>
	 */
	public static List<Map<String, Object>> toDict() {
		if(cache != null){
			return cache;
		}
		
		if(cache == null){
			synchronized(PatientMemberGenderEnum.class) {
				if(cache == null){
					List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
					for (PatientMemberGenderEnum t : PatientMemberGenderEnum.values()) {
						Map<String, Object> tempMap = new HashMap<String, Object>();
						tempMap.put("value", t.getValue());
						tempMap.put("desc", t.getDesc());
						list.add(tempMap);
					}
					cache = list;
				}
			}
		}
		
		return cache;
	}

	public Integer getValue() {
		return this.value;
	}

	public String getDesc() {
		return this.desc;
	}

	public List<Map<String, Object>> getCache() {
		return this.cache;
	}

}